package chapter16Condition;

/**
 * Object中的wait和notify
 * Created by LinGer on 2019/6/24
 */
public class WaitTest extends Thread{

    public WaitTest(String name){
        super(name);
    }

    @Override
    public void run() {
        //获取当前对象的同步锁
        synchronized (this){
            System.out.println(this.getName() + " wakeup others");
            //唤醒当前对象上的等待线程
            notify();
        }
    }

    public static void main(String[] args) {
        WaitTest ta = new WaitTest("ta");

        synchronized (ta){
            System.out.println(Thread.currentThread().getName() + " start ta");
            ta.start();

            System.out.println(Thread.currentThread().getName() + " block");
            try {
                ta.wait();
            } catch (InterruptedException e) {
                e.printStackTrace();
            }

            System.out.println(Thread.currentThread().getName() + " continue");
        }
    }
}
